package service;

import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


import dao.IAccountDao;
import dao.XmlAccountDaoImpl;
import domain.Account;
import utils.PasswordUtil;

public class AccountServiceImpl implements IAccountService{
 private IAccountDao dao;
	@Override
	public Account login(String username, String password) throws NoSuchAlgorithmException {
		Map<String,Object> resultMap=new HashMap<String,Object>();
		Account account = new Account();
		Account lAccount= new Account();
	try {
		dao=new XmlAccountDaoImpl();
		List<Account> list=	dao.queryAccountsByUsername(username);
		if (list.size()==1) {
			account=(Account) list.get(0);
			String enPass=PasswordUtil.md5Encrypt(password);
			if (enPass.equals(account.getPassword())) {
				lAccount= account;
			}
		}
	} catch (Exception e) {
		e.printStackTrace();
	}
	   return lAccount ;
	}
	
}
